<?php
class FrontendController extends Controller
{
    public $breadcrumbs=array();
    public $logo;

    protected $leftMenuArray=array(
        'home'=>'',
        'catalog'=>'catalog',
        'news'=>'info/news',
        'user'=>'account/index',
    );

    private $leftMenu=array();

    public function init()
    {
        Yii::app()->theme='frontend';

        if(Yii::app()->request->getQuery('language')){
            $lang=Yii::app()->request->getQuery('language');
            Yii::import('application.models.local.Language');
            if(Language::model()->getLang($lang)){
                Yii::app()->language=$lang;
                Yii::app()->user->setState('language', $lang);
            }
            unset($_GET['language']);
            $this->redirect(Yii::app()->createUrl('',$_GET));
        }elseif(Yii::app()->user->hasState('language')){
            Yii::app()->language=Yii::app()->user->getState('language');
        }else{
            Yii::app()->language=Setting::getConfig('default_language');
            Yii::app()->user->setState('language', Yii::app()->language);
        }

        foreach($this->leftMenuArray as $name=>$url){
            $name=Yii::t('main',$name);
            $url=$url ? $this->createUrl($url) : Yii::app()->homeUrl;
            $this->leftMenu[$name]=(object)array(
                'name'=>$name,
                'url'=>$url,
            );
        }

        $this->logo=Yii::app()->file->getImageUrl(Setting::getConfig('main_logo'));

        parent::init();
    }

    public function getLeftMenu()
    {
        return $this->leftMenu;
    }
}